/**
 * 
 */
package com.autonavi.car.si.FileStore.Config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.autonavi.car.si.FileStore.util.ConfigUtil;
import com.autonavi.car.si.FileStore.util.StringUtil;

/**
 * 
 * 文件存储的相关配置
 * 
 * @author kucheng.liao@autonavi.com
 * @date Nov 24, 2014
 * 
 */
public class FileStoreConfig {

	private static Logger log = LoggerFactory.getLogger(FileStoreConfig.class);

	private static final String FILE_STORE_NODE = "FILE_STORE_SLICE";

	private FTPHostManager manager;
	/**
	 * 存储节点数量
	 */
	private int storeSliceNumber = 16;

	/**
	 * @return the storeSliceNumber
	 */
	public int getStoreSliceNumber() {
		return storeSliceNumber;
	}

	/**
	 * @param storeSliceNumber
	 *            the storeSliceNumber to set
	 */
	public void setStoreSliceNumber(int storeSliceNumber) {
		this.storeSliceNumber = storeSliceNumber;
	}

	/**
	 * 初始化
	 * 
	 * @return
	 */
	private FileStoreConfig init() {
		try {
			String number = ConfigUtil.get(FILE_STORE_NODE);
			if (StringUtil.isNotEmpty(number)) {
				storeSliceNumber = Integer.parseInt(number);
			}
			manager = new FTPHostManager();
			manager.init();
		} catch (Exception e) {
			log.error("", e);
		}
		return this;
	}

	private static volatile FileStoreConfig config;

	/**
	 * 获取单例配置
	 * 
	 * @return
	 */
	public static FileStoreConfig getInstance() {
		if (null == config) {
			synchronized (FileStoreConfig.class) {
				if (null == config) {
					config = new FileStoreConfig().init();
				}
			}
		}
		return config;
	}

	/**
	 * @return the manager
	 */
	public FTPHostManager getManager() {
		return manager;
	}

	/**
	 * @param manager the manager to set
	 */
	public void setManager(FTPHostManager manager) {
		this.manager = manager;
	}
	

}
